import regeneratorRuntime from '../../plugins/regenerator-runtime.js'
import { addVisitorFrequency } from '../../utils/encapsulation.js'//数据监控
import { Request_API_CN, Request_API_COM } from '../../utils/index.js'//封装请求
import login from '../../api/login.js'
import { prefix, surface } from '../../api/config.js';
const app = getApp()
let _this
Page({
  data: {
    Active:1,//全局CSS样式
    text1:'',
    text2:'',
  },
  onLoad: function () {
    _this = this;
    _this.Associator()
  },
  Associator:()=>{//会员规则
    Request_API_CN(prefix+'/associator', 'POST', {})
    .then((res)=>{
      _this.setData({
        text1: res.data.data.text1,
        text2: res.data.data.text2
      })
      console.log(res)
    })
  },
  bapBtn:(e)=>{//点击上方tab选项卡
    // console.log(e.currentTarget.dataset.id)
    if (e.currentTarget.dataset.id != _this.data.Active){
      _this.setData({
        Active: e.currentTarget.dataset.id
      })
    }
    console.log(_this.data.Active)
  },
  Recharge:()=>{
    Request_API_CN(prefix+'/unifiedorder', 'POST', { openid: app.globalData.openid, price: _this.data.Active == 1 ? 10 : 100, ordertype: 3 })
    .then((res)=>{
      console.log(res)
      _this.wxPay(res.data.data)
    })
  },
  wxPay: function (data) { //调用微信支付
    wx.requestPayment({
      timeStamp: data.timeStamp + '',
      nonceStr: data.nonceStr,
      package: data.package,
      signType: 'MD5',
      paySign: data.paySign,
      success: res => {
        console.log(res)
        wx.showToast({
          title: '升级会员成功!'
        })
      },
      fail: res => {
        console.log(res)
      }
    })
  },
})